package cs271.examples.expressiontrees;
import junit.framework.TestCase;


public class ExpressionTreeTest extends TestCase {
	
	public void testAddition() {
		//test 5 + 6 = 11
		AbstractExprTreeElement root = new AdditionElement();
		root.setLeft(new ValueElement(5));
		root.setRight(new ValueElement(6));
		
		assertEquals(root.evaluate(), 11);
	}
	
	public void testSubtraction() {
		//test 5 - 6 = -1
		AbstractExprTreeElement root = new SubtractionElement();
		root.setLeft(new ValueElement(5));
		root.setRight(new ValueElement(6));
		
		assertEquals(root.evaluate(), -1);
	}
	
	public void testComplexAddSubtract() {
		//test 5 + (9-8) - 2 = 4
		AbstractExprTreeElement root = new SubtractionElement();
		
		AbstractExprTreeElement leftSide = new AdditionElement();
		leftSide.setLeft(new ValueElement(5));
		AbstractExprTreeElement leftSideRight = new SubtractionElement();
		leftSideRight.setLeft(new ValueElement(9));
		leftSideRight.setRight(new ValueElement(8));
		leftSide.setRight(leftSideRight);
		
		root.setLeft(leftSide);
		root.setRight(new ValueElement(2));
		
		assertEquals(root.evaluate(), 4);
	}
}
